package com.example.xd.javatest.factory_test.sample;

import com.example.xd.javatest.factory_test.Audi;
import com.example.xd.javatest.factory_test.Byd;
import com.example.xd.javatest.factory_test.Car;

/**
 * @auther XuDan on 2020/6/16.
 * 调用者只需知道CarFactory和Car
 * 每次新创建一个车就需要修改代码(违反开闭原则)
 */
public class CarFactory {
    public static Car createCar(String type) {
        switch (type) {
            case "奥迪":
                return new Audi();
            case "比亚迪":
                return new Byd();
            default:
                return null;
        }
    }
}
